
//!============================================================================
//!<Source> Vertex
//!----------------------------------------------------------------------------

#ifndef HasVertexPosition
#error \"Mandatory shader input VertexPosition not defined\"
#endif

//!----------------------------------------------------------------------------
// Shader inputs

// Vertex position default type (vec3)
// It can be vec3 or vec4
#ifndef VertexPositionType
#define VertexPositionType vec3
#endif
// Vertex position
in VertexPositionType ds_VertexPosition;

// Vertex color default type (vec4)
// It can be only vec4
#ifndef VertexColorType
#define VertexColorType vec4
#endif
// Vertex color
in VertexColorType ds_VertexColor;

// Vertex normal default type (vec3)
// It can be only vec3
#ifndef VertexNormalType
#define VertexNormalType vec3
#endif
// Vertex normal
in VertexNormalType ds_VertexNormal;

//!----------------------------------------------------------------------------
// Shader outputs

// Vertex color
out vec4 ds_VertexColorOut;

//!----------------------------------------------------------------------------
// Entry point

//!<Include> IProjectVertex.sl
//!<Include> ILightModel.sl

void main()
{
	// Compute transformed vertex position
	gl_Position = ProjectVertexPosition(ds_VertexPosition);

	// Determine vertex color
#if defined(HasVertexNormal) && defined(HasILightModel)
	// Determine vertex color by lights
	ds_VertexColorOut = ComputeLightsContribution(gl_Position, ds_VertexNormal);
#elif defined(HasVertexColor)
	// Determine vertex color by input
	ds_VertexColorOut = ds_VertexColor;
#endif
}

//!============================================================================
//!<Source> Fragment
//!----------------------------------------------------------------------------

//!----------------------------------------------------------------------------
// Shader inputs

// Vertex color
in vec4 ds_VertexColorOut;

//!----------------------------------------------------------------------------
// Shader outputs

// Fragment color
out vec4 ds_FragmentColor;

//!----------------------------------------------------------------------------
// Entry point

void main()
{
#if defined(HasVertexColor) || defined(HasILightModel)
	// Vertex color: interpolate vertices colors
	ds_FragmentColor = ds_VertexColorOut;
#else
	// No fragment algorthm selection: default to uniform white color
	ds_FragmentColor = vec4(1.0, 1.0, 1.0, 1.0f);
#endif
}

//!============================================================================
//! Implemetation notes
//!----------------------------------------------------------------------------
//! 
//!----------------------------------------------------------------------------